<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언
    $incCd 			= $_POST['incCd'];
    $incSeq 		= $_POST['incSeq'];

	// Table 이름 선언
	$tbname = "tblIncome";

    $curDt =date("Y-m-d");

    $query = "SELECT A.incCd, A.compCd, A.income, A.incomeDt, A.billCd, A.invoiceCd, A.invoiceMemo ";
    $query .= ", REPLACE(CONVERT(varchar, CAST(A.amount AS money), 1), '.00', '') amount ";
    $query .= ", REPLACE(CONVERT(varchar, CAST(A.orgAmount AS money), 1), '.00', '') orgAmount ";
    $query .= ", REPLACE(CONVERT(varchar, CAST(A.tax AS money), 1), '.00', '') tax ";
    $query .= ", A.memo, A.flag";
    $query .= " FROM {$tbname} A WHERE incCd={$incCd}";
    $query = iconvEncode($query);

    $logger->debug($query ."<br>[#FROM:" . $G_remote_ip."#]"); ## 쿼리 로그 작성
    $result = makeJSONArray($query,$tbname);

    if ($incSeq) {
        $query = "SELECT REPLACE(CONVERT(varchar, CAST(B.amount AS money), 1), '.00', '') incAmount";
        $query .= ", B.incSeq, B.actionDt, B.bankDt, B.memo incMemo, B.flag incFlag";
        $query .= " FROM tblIncResult B WHERE incSeq={$incSeq}";
        $query = iconvEncode($query);
        $incResult = makeJSONArray($query,"tblIncResult");
        $result["INCRESULT"] = $incResult;
    }

    $output = json_encode($result);
    $output = urldecode($output);
    $output = iconvDecode($output);
    $output = str_replace("<br />", "", $output);
    echo $output;
    $logger->debug($compCd ."//" .$output ."<br>[#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>